<admintpl file="header" />
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li ><a  href="{:U('AdminPackage/index',array('op'=>'package_month'))}">月套餐</a></li>
        <li><a href="{:U('AdminPackage/index',array('op'=>'package_add'))}">增量包</a></li>
        <li class="active"><a href="{:U('AdminPackage/add',array('id'=>empty($item['package_id'])?'':$item['package_id']))}" target="_self"><if condition="!empty($item['package_id'])">修改<else/>新增</if></a></li>
    </ul>
    <form action="{:U('AdminPackage/add_post')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data" onsubmit="return check_form();">
        <div class="row-fluid">
            <div class="span9">
                <table class="table table-bordered">
                    <tr>
                        <th>套餐类型 <span class="form-required">*</span></th>
                        <td>
                            <if condition="empty($item['package_id']) || (!empty($item['package_id']) && $item['package_type'] != 2)">
                            <label class="checkbox inline">
                            <input value="1" <if condition="$item['package_type'] != 2">checked</if> type="radio" name="package_type" onchange="change_package()" >&nbsp;&nbsp;月套餐&nbsp;&nbsp;
                            </label>
                            </if>

                            <if condition="empty($item['package_id']) || (!empty($item['package_id']) && $item['package_type'] != 1)">
                            <label class="checkbox inline">
                            <input value="2" <if condition="$item['package_type'] == 2">checked</if> type="radio" name="package_type" onchange="change_package()">&nbsp;&nbsp;增量包&nbsp;&nbsp;
                            </label>
                            </if>

                        </td>
                    </tr>

                    <tr>
                        <th>流量(M) <span class="form-required">*</span></th>
                        <td>
                            <input type="text" <if condition="$is_bind">readonly</if>  name="package_data" <if condition="$item['package_id']==1">readonly</if> class="require number" id="package_data" value="{$item.package_data}" style="width: 400px" placeholder="请输入流量(M)">
                            <if condition="$item['package_type'] != 2">
                                <span style="color:red" class="package_data1"><if condition="$is_bind">已有卡正在关联此套餐，流量值无法修改<else/>最低流量为30M，且为10的倍数或1024的倍数</if></span>
                                <span style="display:none;color:red" class="package_data2"><if condition="$is_bind">已有卡正在关联此套餐，流量值无法修改<else/>最低流量为10M，且为10的倍数或1024的倍数</if></span>
                            <else/>
                                <span style="display:none;color:red" class="package_data1"><if condition="$is_bind">已有卡正在关联此套餐，流量值无法修改<else/>最低流量为30M，且为10的倍数或1024的倍数</if></span>
                                <span style="color:red" class="package_data2"><if condition="$is_bind">已有卡正在关联此套餐，流量值无法修改<else/>最低流量为10M，且为10的倍数或1024的倍数</if></span>
                            </if>
                        </td>
                    </tr>

                    <tr>
                        <th>价格 <span class="form-required">*</span></th>
                        <td>
                            <input type="text"  name="package_price" class="require" id="package_price" value="{$item.package_price}" style="width: 400px" placeholder="请输入价格">
                        </td>
                    </tr>

                    <!--<tr>-->
                        <!--<th>流量标题 <span class="form-required">*</span></th>-->
                        <!--<td>-->
                            <!--<input type="text" name="package流量标题data" class="require" id="package流量标题data" value="{$item.package流量标题data}" style="width: 400px" placeholder="请输入流量标题">-->
                        <!--</td>-->
                    <!--</tr>-->

                    <!--<tr>-->
                        <!--<th>价格标题 <span class="form-required">*</span></th>-->
                        <!--<td>-->
                            <!--<input type="text" name="package价格标题price" class="require" id="package价格标题price" value="{$item.package价格标题price}" style="width: 400px" placeholder="请输入价格标题">-->
                        <!--</td>-->
                    <!--</tr>-->
                </table>
            </div>
        </div>
        <div class="form-actions">
            <input type="hidden" name="id" value="{$item.package_id}"/>
            <button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
            <a class="btn" href="{:U('AdminPackage/index')}">返回</a>
        </div>
    </form>
</div>
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
<script>
    function check_form(){
        var package_type = $("input[name='package_type']:checked").val();
        console.log(package_type);
        var package_data = $("#package_data").val();
        var package_price = $("#package_price").val();
        if(package_data == ''){
            alert("流量值不能为空！");return false;
        }
        if(isNaN(package_data)){
            alert("流量值输入有误！");return false;
        }

        if(package_price == ''){
            alert("价格不能为空！");return false;
        }
        if(isNaN(package_price)){
            alert("价格输入有误！");return false;
        }
        return true;
    }
    function change_package(){
        var package_type = $("input[name='package_type']:checked").val();
        if(package_type == 1){
            $(".package_data1").show();
            $(".package_data2").hide();
        }else{
            $(".package_data1").hide();
            $(".package_data2").show();
        }
    }
</script>
</body>
</html>